//package com.example.springboottemplate.Config.Netty;
//import io.netty.bootstrap.ServerBootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.EventLoopGroup;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.nio.NioServerSocketChannel;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.PostConstruct;
//import javax.annotation.PreDestroy;
//
///*
//*   NettyServer
// */
//
//@Component
//public class NettyServer {
//    private final int port = 8080;
//
//    private EventLoopGroup bossGroup;
//    private EventLoopGroup workerGroup;
//    private ChannelFuture channelFuture;
//
//    @PostConstruct
//    public void start() throws Exception {
//        bossGroup = new NioEventLoopGroup();
//        workerGroup = new NioEventLoopGroup();
//
//        try {
//            ServerBootstrap bootstrap = new ServerBootstrap();
//            bootstrap.group(bossGroup, workerGroup)
//                    .channel(NioServerSocketChannel.class)
//                    .childHandler(new NettyServerInitializer());
//
//            channelFuture = bootstrap.bind(port).sync();
//        } catch (Exception e) {
//            stop();
//            throw e;
//        }
//    }
//
//    @PreDestroy
//    public void stop() {
//        bossGroup.shutdownGracefully();
//        workerGroup.shutdownGracefully();
//
//        try {
//            channelFuture.channel().closeFuture().sync();
//        } catch (InterruptedException e) {
//            Thread.currentThread().interrupt();
//        }
//    }
//}
